package com.common.presenter;

import java.lang.ref.Reference;
import java.lang.ref.WeakReference;

/**
 * Created by Administrator on 2017/2/11.
 */

public class BasePresenter<V> {
    protected Reference<V> mViewRef;        //View接口弱引用

    /**
     * 建立弱引用
     * @param view
     */
    public void attachView(V view){
        mViewRef = new WeakReference<V>(view);
    }

    /**
     * 是否存在引用
     * @return
     */
    public boolean isViewAttached(){
        return mViewRef != null && mViewRef.get()!=null;
    }

    /**
     * 取消若引用
     */
    public void detachView(){
        if(mViewRef != null){
            mViewRef.clear();
            mViewRef = null;
        }
    }
}
